<?php
/**
 * Medical Center Header Block
 *
 * @author Xavier VILAIN
 * @package Nawa
 * @license
 */

use Fox\Message;
use Nawa\MedicalStudy;
use Fox\Html\Header\Image;
use Nawa\Messages;
use Fox\Dao\SqlFragment;
use Nawa\MedicalCenter;
use Fox\Html\Screen;
$xview = Xview::instance();
$screen = new Screen('sMedicalCenter','update');
$screen->mainTitle(new Image("medicalcenter","<div class=\"page-title\">".Msg(Messages::BUNDLE,Messages::LABEL_MEDICAL_CENTER_UPDATE)."</div>"));

$xview = Xview::instance();
$mc = $xview->component('medicalcenters','object',array('mcid' => $xview->val('mcid')));
$data = $mc->getData();
foreach($mc->medicalStudies() as $medicalStudyPartner)
{
	$data['gMedicalStudies'][] = Fox\Dao::load(MedicalStudy::className(),$medicalStudyPartner->msid);
}
// Header
$blHead = $xview->component("medicalcenters","head");
$screen->add($blHead);
// Address Data
$blAddress = Xview::instance()->component("customers", "address");
$screen->add($blAddress);
// Medical Studies List
$blMedicalStudies = Xview::instance()->component("medicalcenters", "medicalstudies");
$screen->add($blMedicalStudies);
$screen->initialize($data);

if($screen->submitted())
{
	$fields = $screen->get();
	if(!$screen->errors())
	{
		try {
			$mc->setFields($fields);
			$mc->prepareUpdate(MedicalCenter::CHANGE_DEFAULT);
			if($mc->update())
			{
				Message::Success(Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_UPDATE,$mc->name1));
			}
		}
		catch(Fox\Object\Exception\Save $e)
		{
			Message::Error($e->getMessage());
		}
	}
}
echo $screen->display();